﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.Entity;
using System.Runtime.Remoting.Messaging;
using Models;

namespace DAL
{
    /// <summary>
    /// 数据源工厂
    /// </summary>
    public class DBFactory
    {
        /// <summary>
        /// 返回唯一的EF上下文操作类
        /// </summary>
        /// <returns></returns>
        public static DbContext CreateDbContext()
        {
            //从上下文中查找dbcontext键对应的值
            DbContext db = (DbContext)CallContext.GetData("dbcontext");
            //如果db没有找到值，则为其创建EF实例，并将其写入到上下文中
            if(db==null)
            {
                db = new bds271453216_dbEntities();
                CallContext.SetData("dbcontext", db);
            }
            return db;
        }
    }
}
